package sg.edu.nus.dashboard.main.model
{
	import com.adobe.cairngorm.model.IModelLocator;
	
	import sg.edu.nus.dashboard.advisor.model.AdvisorModelLocator;
	import sg.edu.nus.dashboard.baseline.model.BaselineModelLocator;
	import sg.edu.nus.dashboard.sql.model.SQLModelLoacator;
	import sg.edu.nus.dashboard.stat.model.StatModelLocator;
	
	[Bindable]
	public class AppModelLocator implements IModelLocator
	{
		
		public var stat:StatModelLocator = new StatModelLocator();
		public var advisor:AdvisorModelLocator = new AdvisorModelLocator();
		public var baseline:BaselineModelLocator = new BaselineModelLocator();
		public var sql:SQLModelLoacator = new SQLModelLoacator();
		
		public var connectInfoStr:String = " >> No Connection";
		
		// Parameter for switching views
		public var selectedModel:int = 0;
		
		// Main model parameter definition
		public static const DASHBOARD:int = 0;
		public static const ADVISOR:int = 1;
		public static const BASELINE_CONFIGURE:int = 2;
		public static const DEBUG_INTERFACE:int = 3;
		
		// Single instance of modellocator
		private static var instance:AppModelLocator;
		
		public function AppModelLocator(enforcer:SingletonEnforcer) {
			if(enforcer == null) {
				throw new Error("error");
			}
		}
		
		// Return the single instance
		public static function getInstance():AppModelLocator {
			if(instance == null) {
				instance = new AppModelLocator(new SingletonEnforcer());
			}
			return instance;
		}
	}
}

/**
 * For enforcing singleton
 */
class SingletonEnforcer{}